type int = number;
//class StringHelper

    export  class StringHelper
    {
       

        public static getCharLength(arg1: string): int
        {
            var loc4=NaN;
            var loc1=arg1.length;
            var loc2=0;
            var loc3=0;
            while (loc3 < loc1) 
            {
                if ((loc4 = arg1.charCodeAt(loc3)) > 255 || loc4 < 0) 
                {
                    loc2 = loc2 + 2;
                }
                else 
                {
                    loc2 = loc2 + 1;
                }
                ++loc3;
            }
            return loc2;
        }

        public static trim(arg1: string): string
        {
            if (arg1 == null) 
            {
                return "";
            }
            var loc1=0;
            while (StringHelper.isWhitespace(arg1.charAt(loc1))) 
            {
                ++loc1;
            }
            var loc2=(arg1.length - 1);
            while (StringHelper.isWhitespace(arg1.charAt(loc2))) 
            {
                --loc2;
            }
            if (loc2 >= loc1) 
            {
                return arg1.slice(loc1, loc2 + 1);
            }
            return "";
        }

        public static isWhitespace(arg1: string): Boolean
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case " ": case "　": case "\t": case "\r": case "\n": case "":
                {
                    return true;
                }
                default:
                {
                    return false;
                }
            }
        }

        public static getString(arg1: string): string
        {
            return arg1 != null ? arg1 : "";
        }

        public static substitute(arg1: string, ... rest): string
        {
            var loc2=null;
            if (arg1 == null) 
            {
                return "";
            }
            var loc1=rest.length;
            if (loc1 == 1 && rest[0] is Array) 
            {
                loc1 = (loc2 = rest[0] as Array<any>).length;
            }
            else 
            {
                loc2 = rest;
            }
            var loc3=0;
            while (loc3 < loc1) 
            {
                arg1 = arg1.replace(new RegExp("\\{" + loc3 + "\\}", "g"), loc2[loc3]);
                ++loc3;
            }
            return arg1;
        }
    }
